﻿using System.Collections.ObjectModel;
using System.Xml.Serialization;
using ElectronicCommerce.Framework.Configuration.Attributes;

namespace ElectronicCommerce.Framework.Web.Configuration.Resource
{
    [ConfigFile("PageProperties.config")]
    [XmlRoot("PageList")]
    public class PagePropertiesConfiguration
    {
        [XmlElement("Common")]
        public CommonStyle CommonProperties { get; set; }

        [XmlElement("Page")]
        public PagePropertiesCollection PageList { get; set; }
    }

    public class PagePropertiesCollection : KeyedCollection<string, SinglePage>
    {
        protected override string GetKeyForItem(SinglePage item)
        {
            return item.Alias;
        }
    }

    public class CommonCollection : KeyedCollection<string, CommonEntity>
    {
        protected override string GetKeyForItem(CommonEntity item)
        {
            return item.Alias;
        }
    }

    public class SinglePage
    {
        [XmlAttribute("alias")]
        public string Alias { get; set; }

        [XmlElement("JsList")]
        public CommonList JSInfos { get; set; }

        [XmlElement("CssList")]
        public CommonList CssInfos { get; set; }

        [XmlElement("ErrorList")]
        public CommonList ErrorInfos { get; set; }
    }

    public class CommonStyle
    {
        [XmlElement("JsList")]
        public CommonList JSInfos { get; set; }

        [XmlElement("CssList")]
        public CommonList CssInfos { get; set; }
    }

    public class CommonList
    {
        [XmlElement("CommonEntity")]
        public CommonCollection InfoList { get; set; }
    }

    public class CommonEntity
    {
        [XmlAttribute("alias")]
        public string Alias { get; set; }
    }
}
